#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/27 11:50
# @Author: hekang
# @Email: 591785757@qq.com
# @File：draft_page.py
from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage
from appium.webdriver.common.touch_action import TouchAction


class DraftPage(BasePage):
    '''定位器'''
    select_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]"
                  "/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")
    delete_locator = (
        By.ANDROID_UIAUTOMATOR, "new UiSelector().className(\"android.widget.Button\").textContains(\"删除\")"
                                ".resourceId(\"android:id/button1\")")
    assert_delete_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_title\"]")

    # 选择草稿
    def draft_select(self):
        self.find_element(self.select_locator).click()

    # 退出草稿箱
    def draft_exit(self):
        self.driver.tap([(0, 72), (132, 204)], 500)

    # 删除草稿
    def draft_delete(self):
        self.find_element(self.delete_locator).click()

    # 长按选择
    def draft_long_press(self):
        action = TouchAction(self.driver)
        action.long_press(x=600, y=450, duration=2000).perform()

    # 获取草稿箱数量
    def assert_delete(self):
        return self.find_element(self.assert_delete_locator).text
